const middleWare1 = async (req, res, next) => {
  console.log('middleWare1');
  const res1 = await next()
  console.log('res1', res1);
}

const middleWare2 = async (req, res, next) => {
  console.log('middleWare2');
  const res2 = await next()
  console.log('res2', res2);
  return Promise.resolve({ from: 2, msg: 'middleWare2 result' })
}

const middleWare3 = async (req, res, next) => {
  console.log('middleWare3');
  const res3 = await next()
  console.log('res3', res3);
  return Promise.resolve({ from: 3, msg: 'middleWare3 result' })
}

const middleWares = [middleWare1, middleWare2, middleWare3]

const run = (req, res) => {
  const next = () => {
    const middleWare = middleWares.shift()
    if (middleWare && typeof middleWare === 'function') {
      return Promise.resolve(middleWare(req, res, next))
    }
  }
  next()
}

run({}, {})
